package formes;

import java.util.ArrayList;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

/**
 * Forme de type Rectangle <br \>
 * herite de Forme
 * 
 * @author Sebastien
 */
public class Rectangle extends Forme
{

    private Point point2;
	private int height;
	private int width;

    public Rectangle(ArrayList<String> info)
    {
        setType(info.get(1));
        setId(Integer.parseInt(info.get(0)));

        setPoint1(new Point(Integer.parseInt(info.get(2)), Integer.parseInt(info.get(3))));
        point2 = (new Point(Integer.parseInt(info.get(4)), Integer.parseInt(info.get(5))));

        height = calcul(getPoint1().y, point2.y);
        width = calcul(getPoint1().x, point2.x);

    }

    /**
     * @param g
     *            le graphics Fonction: dessiner la forme
     */
    public void draw(Graphics g)
    {
    	g.setColor(Color.RED);
        g.fillRect(getPoint1().x, getPoint1().y, height, width);
    }
    
    public double calculAire()
    {
        int coteX = Math.abs(point2.x - getPoint1().x);
        int coteY = Math.abs(point2.y - getPoint1().y);
        double aire = coteX*coteY;    
        return aire;
    }
    
    
    /**
     * Fonction: calcul la distance maximum entre deux point
     * @Return: le distance entre deux point
     */
    public double calculLigne()
    {
        int coteX = Math.abs(point2.x - getPoint1().x);
        int coteY = Math.abs(point2.y - getPoint1().y);
        
        double ligne =  Math.sqrt(coteX*coteX + coteY*coteY);
        
        return ligne;          
    }
    

    /**
     * Calcul largeur/longeur
     * 
     * @param x
     *            la position en X
     * @param y
     *            la position en Y
     * @return la distance entre 2 point
     */
    public int calcul(int x, int y)
    {
        return Math.abs(x - y);
    }
    
    
    

}
